from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import *


class LineCheckBoxHLayout(QWidget):
    def __init__(self, value=None):
        super().__init__()
        self.check_box = QCheckBox()
        self.label = QLabel(value)
        self.hlayout = QHBoxLayout()
        self.hlayout.setContentsMargins(0, 0, 0, 0)
        self.setUI()

    def setUI(self):
        self.hlayout.setAlignment(Qt.AlignLeft)

        self.check_box.setStyleSheet("margin-top: 5px")
        self.check_box.stateChanged.connect(lambda:self.checkboxStateChange(self.check_box))
        self.hlayout.addWidget(self.check_box, alignment=Qt.AlignTop)

        self.label.setMinimumWidth(330)
        self.label.setWordWrap(True)
        self.label.setStyleSheet('font-family: "微软雅黑","Times New Roman", Times, serif;font-size: 14px;')
        self.label.setTextInteractionFlags(Qt.TextSelectableByMouse)

        self.hlayout.addWidget(self.label, alignment=Qt.AlignBaseline)
        self.setLayout(self.hlayout)

    def checkboxStateChange(self, cb):
        if self.check_box.isChecked():
            self.label.setStyleSheet("text-decoration: line-through; color: gray")
        else:
            self.label.setStyleSheet('font-family: "微软雅黑","Times New Roman", Times, serif;font-size: 14px;')